package com.umeox.iqibla.qimi_app

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.lifecycle.lifecycleScope
import com.umeox.moto.watch.themes.app.ThemeAppCompatActivity
import com.umeox.moto.watch.themes.widget.TextView
import kotlinx.coroutines.launch

class WelcomeActivity : ThemeAppCompatActivity() {

    private lateinit var ivConfirm: TextView
    private lateinit var tvTimer: TextView


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_welcome)
        ivConfirm = findViewById(R.id.iv_confirm)
        tvTimer = findViewById(R.id.tv_timer)

        ivConfirm.setOnClickListener {
            val intent = Intent(this, ChatActivity::class.java)
            intent.putExtra("agentId", BuildConfig.GRIL_AGENT_ID)
            startActivity(intent)
            finish()
        }

        checkAvailableTimes()
    }

    @SuppressLint("StringFormatInvalid")
    private fun checkAvailableTimes() {
        lifecycleScope.launch {
            QiHelper.initAvailableTimes()
            val times = QiHelper.getAvailableTimes()
            if (times <= 0) {
                ivConfirm.visibility = View.GONE
                tvTimer.visibility = View.VISIBLE
                tvTimer.text = getString(R.string.qimi_dont_use)
            } else {
                ivConfirm.visibility = View.VISIBLE
                tvTimer.visibility = View.VISIBLE
                tvTimer.text = getString(R.string.qimi_tip, times)
            }
        }

    }

} 